package main

import (
	"fmt"
	"sync"
	"time"
)

var m = new(sync.Mutex)
var good int8 = 3
var hold = make(chan bool)

func main() {
	go lockKill()
	go lockKill()
	go lockKill()
	go lockKill()
	lockKill()
	<- hold
}

func lockKill() {
	m.Lock()
	// 进入秒杀区域
	if good == 0 {
		fmt.Println("秒杀结束~")
		hold <- false
		return
	}
	time.Sleep(1 * time.Second)
	good--
	m.Unlock()
	fmt.Printf("抢到一个名额,还剩 %d\n", good)
}